/**
 * @param {number[]} nums
 * @return {void} Do not return anything, modify nums in-place instead.
 */
var sortColors = function(nums) {
  let count = [0, 0, 0];
  for(let i = 0; i < nums.length; i++) {
    count[nums[i]]++;
  }
  for(let i = 0; i < nums.length; i++) {
    if(count[0]) {
      nums[i] = 0;
      count[0]--;
    } else if (count[1]){
      nums[i] = 1;
      count[1]--;
    } else {
      nums[i] = 2;
      count[2]--;
    }
  }
  return nums;
};
let nums = [2,0,2,1,1,0];
console.log(sortColors(nums));
nums = [2,0,1];
console.log(sortColors(nums));
